package com.hisense.ovcloud.asop.tools;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * @author: yangweiping1
 * @description:
 * @date: 2025/6/5 13:30
 */
public class DateUtils {

    public static String getDateStr(long timestamp, String pattern) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp),
                ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String getQueryStartDateStr(long timestamp) {
        timestamp = timestamp == 0 ? getDaysAgo(10) : timestamp;
        return getDateStr(timestamp, "yyyyMMdd");
    }

    public static String getQueryEndDateStr(long timestamp) {
        timestamp = timestamp == 0 ? System.currentTimeMillis() : timestamp;
        return getDateStr(timestamp, "yyyyMMdd");
    }

    public static long getDaysAgo(int day) {
        // 返回n天前的时间戳
        return System.currentTimeMillis() - day * 24 * 60 * 60 * 1000L;
    }
}
